package com.yisu.auction.api.web.controller;

import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import com.yisu.auction.api.core.service.ISystemNoticeService;
import com.yisu.auction.api.domain.request.systemPackage.SystemNoticeRequest;
import com.yisu.auction.api.domain.response.systemPackage.SystemNoticeResponse;
import com.yisu.auction.api.domain.vo.indexPackageVos.SystemConfigVo;
import com.yisu.auction.api.domain.vo.systemPackageVos.SystemNoticeTypeVo;
import com.yisu.auction.api.domain.vo.systemPackageVos.SystemNoticeVo;
import com.yisu.auction.api.web.interceptor.IAuthVerifyAnnotation;
import com.yisu.auction.ewf.common.enums.LoginTypeEnum;
import com.yisu.auction.ewf.common.enums.ResponseCode;
import com.yisu.auction.ewf.common.web.JsonResult;
import com.yisu.auction.ewf.entity.SystemNotice;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

/**
 * author: 黄萧林
 * Business Description：
 * createTime：2017/9/1
 */
@Controller
@RequestMapping(value = "/systemNotice")
public class SystemNoticeController extends BaseController {
    @Resource
    private ISystemNoticeService iSystemNoticeService;


    /**
     * author;黄萧林
     * Business Description:获取系统公告详情数据
     *
     * @return
     */
    @RequestMapping(value = "/getSystemNoticeListByMsgType", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    @ResponseBody
    @IAuthVerifyAnnotation(Desc = "登录验证", LoginTypeEnum = LoginTypeEnum.NO_NEED_LOGIN)
    public JsonResult getSystemNoticeListByMsgType(SystemNoticeRequest systemNoticeRequest) {
        SystemNoticeResponse systemNoticeResponse = new SystemNoticeResponse();
        JsonResult jsonResult = new JsonResult();
        boolean operateStatus = false;
        switch (systemNoticeRequest.getMsgType()) {
            case 1:
                List<SystemNoticeVo> systemNoticeList = iSystemNoticeService.getSystemNoticeListByMsgType(systemNoticeRequest);
                if (CollectionUtils.isEmpty(systemNoticeList)) {
                    systemNoticeList = Lists.newArrayList();
                }
                systemNoticeResponse.setSystemNoticeVos(systemNoticeList);
                jsonResult.setData(systemNoticeResponse);
                operateStatus = true;
                break;
            case 2:
                if (!StringUtils.isEmpty(systemNoticeRequest.getUserToken())) {
                    this.userToken = systemNoticeRequest.getUserToken();
                    systemNoticeRequest.setMemberId(String.valueOf(this.getToken().getMemberId()));
                    List<SystemNoticeVo> systemNoticeVos = iSystemNoticeService.getSystemNoticeListByMsgType(systemNoticeRequest);
                    if (CollectionUtils.isEmpty(systemNoticeVos)) {
                        systemNoticeVos = Lists.newArrayList();
                    }
                    systemNoticeResponse.setSystemNoticeVos(systemNoticeVos);
                    jsonResult.setData(systemNoticeResponse);
                    operateStatus = true;
                } else {
                    return new JsonResult(ResponseCode.FAILURE.code, "缺少Token！");
                }
                break;
        }
        if (operateStatus) {
            return jsonResult;
        }
        return new JsonResult(ResponseCode.FAILURE.code, "请输入正确参数！");
    }

}
